import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import dictService from '/@/api/cn/core/dict/dictService'

import type { Dict } from '/@/model/cn/core/dict/eo/Dict'
import type { DictQO } from '/@/model/cn/core/dict/qo/DictQO'
import type { DictVO } from '/@/model/cn/core/dict/vo/DictVO'
import type { DictAndValueVO } from '/@/model/cn/core/dict/vo/DictAndValueVO'

interface DictState {
}

export const useDictStore = defineStore({
  id: 'dict',
  state: (): DictState => ({
  }),
  getters: {
  },
  actions: {
    save(param: Param<Dict>): Promise<Res<Dict>> {
      return new Promise<Res<Dict>>((resolve, reject) => {
        dictService.save(param).then((res: AxiosResponse<Res<Dict>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveBatch(param: Param<Dict>): Promise<Res<Dict>> {
      return new Promise<Res<Dict>>((resolve, reject) => {
        dictService.saveBatch(param).then((res: AxiosResponse<Res<Dict>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    update(param: Param<Dict>): Promise<Res<Dict>> {
      return new Promise<Res<Dict>>((resolve, reject) => {
        dictService.update(param).then((res: AxiosResponse<Res<Dict>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    updateBatch(param: Param<Dict>): Promise<Res<Dict>> {
      return new Promise<Res<Dict>>((resolve, reject) => {
        dictService.updateBatch(param).then((res: AxiosResponse<Res<Dict>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    remove(param: Param<Dict>): Promise<Res<Dict>> {
      return new Promise<Res<Dict>>((resolve, reject) => {
        dictService.remove(param).then((res: AxiosResponse<Res<Dict>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    removeBatch(param: Param<Dict>): Promise<Res<Dict>> {
      return new Promise<Res<Dict>>((resolve, reject) => {
        dictService.removeBatch(param).then((res: AxiosResponse<Res<Dict>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    count(param: Param<DictQO>): Promise<Res<Dict>> {
      return new Promise<Res<Dict>>((resolve, reject) => {
        dictService.count(param).then((res: AxiosResponse<Res<Dict>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pk(param: Param<DictQO>): Promise<Res<Dict>> {
      return new Promise<Res<Dict>>((resolve, reject) => {
        dictService.pk(param).then((res: AxiosResponse<Res<Dict>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    query(param: Param<DictQO>): Promise<Res<Dict>> {
      return new Promise<Res<Dict>>((resolve, reject) => {
        dictService.query(param).then((res: AxiosResponse<Res<Dict>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    paging(param: Param<DictQO>): Promise<Res<Dict>> {
      return new Promise<Res<Dict>>((resolve, reject) => {
        dictService.paging(param).then((res: AxiosResponse<Res<Dict>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    countVo(param: Param<DictQO>): Promise<Res<DictVO>> {
      return new Promise<Res<DictVO>>((resolve, reject) => {
        dictService.countVo(param).then((res: AxiosResponse<Res<DictVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pkVo(param: Param<DictQO>): Promise<Res<DictVO>> {
      return new Promise<Res<DictVO>>((resolve, reject) => {
        dictService.pkVo(param).then((res: AxiosResponse<Res<DictVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    queryVo(param: Param<DictQO>): Promise<Res<DictVO>> {
      return new Promise<Res<DictVO>>((resolve, reject) => {
        dictService.queryVo(param).then((res: AxiosResponse<Res<DictVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pagingVo(param: Param<DictQO>): Promise<Res<DictVO>> {
      return new Promise<Res<DictVO>>((resolve, reject) => {
        dictService.pagingVo(param).then((res: AxiosResponse<Res<DictVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    getDictAndValueByDictKey(param: Param<DictQO>): Promise<Res<DictAndValueVO>> {
      return new Promise<Res<DictAndValueVO>>((resolve, reject) => {
        dictService.getDictAndValueByDictKey(param).then((res: AxiosResponse<Res<DictAndValueVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    getAllDictValueMapInfo(): Promise<Res<object>> {
      return new Promise<Res<object>>((resolve, reject) => {
        dictService.getAllDictValueMapInfo().then((res: AxiosResponse<Res<object>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useDictStoreWithout() {
  return useDictStore(store)
}
